package MyGO.utils.ArrayfilterUtils;

import MyGO.Form.TrackForm;
import MyGO.property.CheckPro;
import MyGO.property.Medicine;

import java.util.List;
import java.util.stream.Collectors;

public class ArrayfilterUtils {
    public static List<TrackForm> FilterByTrackFormID(List<TrackForm> trackForms, String ID) {
        return trackForms.stream().filter(trackForm ->
                trackForm.getId().contains(ID)).collect(Collectors.toList());
    }

    public static List<TrackForm> FilterByPatientName(List<TrackForm> trackForms, String name) {
        return trackForms.stream().filter(trackForm ->
                trackForm.getName().contains(name)).collect(Collectors.toList());
    }

    public static List<TrackForm> FilterTrackFormByIDAndPatientName(List<TrackForm> trackForms, String id, String name) {
        return trackForms.stream()
                .filter(trackForm -> (id == null || id.isEmpty() || trackForm.getId().contains(id)) &&
                        (name == null || name.isEmpty() || trackForm.getPatientInfoForm().getName().contains(name)))
                .collect(Collectors.toList());
    }

    public static List<CheckPro> FilterCheackProByIDAndPatientName(List<CheckPro> checkPros, String id, String name) {
        return checkPros.stream()
                .filter(checkPro -> (id == null || id.isEmpty() || checkPro.getId().contains(id)) &&
                        (name == null || name.isEmpty() || checkPro.getName().contains(name)))
                .collect(Collectors.toList());
    }

    public static List<Medicine> FilterMedicineByPinYinAndMedcineName(List<Medicine> medicines, String name, String pinyin) {
        return medicines.stream().filter(medicine -> (name == null || name.isEmpty() || medicine.getName().contains(name)) &&
                (pinyin == null || pinyin.isEmpty() || medicine.getHelpCode().contains(pinyin)))
                .collect(Collectors.toList());
    }
}
